package com.ruibang.glass.equipment.service.impl.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.jdbc.StringUtils;
import com.ruibang.glass.equipment.domain.req.device.DeviceCarReq;
import com.ruibang.glass.equipment.entity.device.DeviceCar;
import com.ruibang.glass.equipment.mapper.device.DeviceCarMapper;
import com.ruibang.glass.equipment.service.DeviceCarService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 专业车辆服务类
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@Slf4j
@Service
public class DeviceCarServiceImpl extends ServiceImpl<DeviceCarMapper, DeviceCar> implements DeviceCarService {

    /**
     * 专业车辆列表
     * @param elevatorReq
     * @return
     */
    @Override
    public IPage<DeviceCar> queryPage(DeviceCarReq elevatorReq) {
        return baseMapper.queryDeviceCarInfo(new Page<>(elevatorReq.getPageNo(), elevatorReq.getPageSize()), elevatorReq);
    }

    /**
     * 跟新
     * @param deviceCar
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultBody updateOrAddById(DeviceCar deviceCar) {
        if (StringUtils.isNullOrEmpty(deviceCar.getId())) {
            baseMapper.insert(deviceCar);
            return ResultBody.success();
        }
        baseMapper.updateById(deviceCar);
        return ResultBody.success();
    }
}
